package serverview;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;

import rmi.*;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.rmi.RemoteException;

public class AddMember extends JDialog {

	/**
	 * @author NeverDie
	 * @since 2012.9.19
	 */
	private static final long serialVersionUID = 1L;

	
	private final JPanel contentPanel = new JPanel();
	private JTextField textField;
	
	//
	ServerView father; 

	/**
	 * Launch the application.
	 */
//	public static void main(String[] args) {
//		try {
//			addMember dialog = new addMember();
//			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
//			dialog.setVisible(true);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}

	/**
	 * Create the dialog.
	 */
	
	public AddMember(Frame owner, boolean modal) {
		super(owner,modal);
		
		this.father = (ServerView) owner;
		setBounds(100, 100, 300, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			JLabel label = new JLabel("\u4F1A\u5458\u59D3\u540D");
			label.setBounds(41, 60, 54, 15);
			contentPanel.add(label);
		}
		{
			textField = new JTextField();
			textField.setBounds(114, 57, 66, 21);
			contentPanel.add(textField);
			textField.setColumns(10);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
					Member member = new Member();
					member.setName(textField.getText());
					member.setPurchaseAmount(0f);
					try {
						father.getMySQL().add(member);
					} catch (RemoteException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					AddMember.this.setVisible(false);
					return;
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						AddMember.this.setVisible(false);
						return;
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

}
